package com.yc.web.servlets;

import com.yc.web.model.JsonModel;
import com.yc.bean.ShoeStatus;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet(name = "alipayServlet",value = "/alipay.action")
public class alipayServlet extends BaseServlet{
    //点击支付后，查询对应商品信息
    protected void findCartInfo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        int oid = Integer.parseInt(req.getParameter("oid"));

        JsonModel jm = new JsonModel();
        String sql = "select photourl,sdescription,dealprice,num\n" +
                "               from Shoes JOIN ShoePhotos ON Shoes.sid = ShoePhotos.sid,ShoeOrder,resorderitem\n" +
                "               where resorderitem.oid=ShoeOrder.oid and resorderitem.sid=Shoes.sid\n" +
                "                   and ismain='true' and resorderitem.oid=?";
        List<ShoeStatus> list = db.select(ShoeStatus.class,sql,oid);

        jm.setCode(1);
        jm.setObj(list);
        super.writeJson(jm,resp);
    }
    //修改支付状态
    protected void changePayStatus(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JsonModel jm = new JsonModel();
        int oid = Integer.parseInt(req.getParameter("oid"));

        String sql = "update ShoeOrder set paymentstatus = '已支付' where oid=? ";
        int result = db.doUpdate(sql,oid);

        if (result==1){
            jm.setCode(1);
        }else {
            jm.setObj(0);
            jm.setError("修改支付状态失败。。。。。");
        }
        super.writeJson(jm,resp);
    }
}
